import heapq


class Solution:
    def maxProbability(self, n: int, edges: list, succProb: list, start: int,
                       end: int) -> float:
        adj = [[] for _ in range(n)]
        for i in range(len(edges)):
            edge = edges[i]
            prob = succProb[i]
            adj[edge[0]] += [(prob, edge[1])]
            adj[edge[1]] += [(prob, edge[0])]

        queue = [(-1.0, start)]
        ans = 0
        visited = set()
        while queue:
            prob, point = heapq.heappop(queue)
            if point == end:
                ans = -prob
                break
            if point in visited:
                continue
            visited.add(point)
            for nprob, npoint in adj[point]:
                heapq.heappush(queue, (-(nprob * -prob), npoint))

        return ans
